package com.example.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.custom.image.FeedImageView;
import com.example.taigame.R;

public class ListView_Install_Adapter extends BaseAdapter{

	private Context context;
	private List<PackageInfo> mylist;
	private Activity activity;
	
	public ListView_Install_Adapter(Context context,List<PackageInfo> list,Activity activity) {
		this.context = context;
		this.mylist = list;
		this.activity = activity;
	}
	@Override
	public int getCount() {
		return mylist.size();
	}

	@Override
	public Object getItem(int position) {
		return mylist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			vi = inflater.inflate(R.layout.listview_installed_items, null);
			FeedImageView icon = (FeedImageView) vi.findViewById(R.id.imageView1);
			TextView textView = (TextView) vi.findViewById(R.id.textView1);
			PackageInfo app = mylist.get(position);
			textView.setText(activity.getPackageManager().getApplicationLabel(app.applicationInfo).toString());
			try {
				icon.setImageDrawable(context.getPackageManager().getApplicationIcon(app.packageName));
			} catch (NameNotFoundException e) {
				e.printStackTrace();
			}
		return vi;
	}
}
